<template>
	<view class="wrap">
		<u-navbar :is-back="true" title="我的服务" :background="background">
			<view class="navbar-right" slot="right" @click="">
				<u-icon name="plus" color="#ffffff" slot: size="30" style="margin-right: 20rpx;"
					@click="openinfo('/pages/tabBar/my/myServer/serverList')"></u-icon>
			</view>
		</u-navbar>
		<view class="u-p-12">
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="u-p-12" v-for="(item, index) in list1" :key="index">
						<u-lazy-load threshold="-450" border-radius="10" :image="oss+item.image" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-shop">
							已售{{item.buy_count}}
							<u-icon name="more-dot-fill" color="#9b9b9b" size="34" class="u-close"
								@click="showPopup(item.id)">
							</u-icon>
						</view>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="u-p-12" v-for="(item, index) in list2" :key="index">
						<u-lazy-load threshold="-450" border-radius="10" :image="oss+item.image" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-shop">
							已售{{item.buy_count}}
							<u-icon name="more-dot-fill" color="#9b9b9b" size="34" class="u-close"
								@click="showPopup(item.id)">
							</u-icon>
						</view>
					</view>
				</template>
			</u-waterfall>
		</view>

		<!-- <u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore> -->
		<u-popup mode="bottom" v-model="show" class="u-p-24" :mask="false" style="width: 90%;margin: 0 auto;">
			<view class="u-m-b-26 u-p-l-26 u-p-r-26 popupView">
				<u-cell-item icon="arrow-upward" title="置顶"></u-cell-item>
				<u-cell-item icon="trash" title="删除" @click="deletee()"></u-cell-item>
			</view>
			<view class="u-m-b-26 u-p-l-26 u-p-r-26 popupView" @click="cancel()">
				<p style="color: #2f84de;font-size: 24rpx;text-align: center;line-height: 80rpx;">取消</p>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#00a8ff'
				},
				
				show: false,
				loadStatus: 'loadmore',
				oss: 'http://zjmeifeng.oss-cn-beijing.aliyuncs.com/',
				flowList: [],
				list1: [],
				list2: [],
				goods_id: ''
			}
		},
		onLoad() {
			// this.addRandomData();
		},

		onShow() {
			// 
			this.getDoods();
		},
		methods: {
			cancel() {
				this.show = false;
			},
			showPopup(id) {
				this.show = true;
				console.log(id)
				this.goods_id = id;
			},
			getDoods() {
				this.$apiVipCentre.goods({
					limit: '',
					page: ''
				}).then((res) => {
					console.log("医生服务列表: ", res.data.data.items);
					let arr = res.data.data.items;
					let arr1 = [],
						arr2 = [];
					for (let i = 0; i < arr.length; i++) {
						if (i % 2 == 0) {
							arr1.push(arr[i])
						} else {
							arr2.push(arr[i])
						}
					}
					console.log(arr1);
					console.log(arr2);
					this.list1 = arr1;
					this.list2 = arr2;

				}).catch((err) => {
					console.log('request fail', err);
				})
			},

			// 删除服务
			delgoods() {
				this.$apiVipCentre.delgoods({
					goods_id: this.goods_id
				}).then((res) => {
					console.log("医生删除服务: ", res.data.msg);
					if (res.data.msg == "删除成功") {
						uni.showToast({
							title: "删除成功"
						})
					}
				}).catch((err) => {
					console.log('request fail', err);
				})
			},
			deletee() {
				console.log("执行删除操作")
				this.delgoods();

				// 关闭pro
				this.show = false;
				this.getDoods();

			},



			openinfo(url) {
				uni.navigateTo({
					url: url,
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.popupView {
		border-radius: 10rpx;
		background-color: #f4f4f7;
	}

	.u-close {
		float: right;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}
</style>
